﻿using System;

namespace KPI
{
	public partial class directpage : System.Web.UI.Page
	{
		protected void Page_Init(object sender, EventArgs e)
		{
			if(!IsPostBack)
			{
				var userName = CommonHelper.QueryString("username");

				if(!string.IsNullOrWhiteSpace(userName))
				{
					using(var userRepository = new DataAccess.Repository.UserRepository())
					{
						var u2 = userRepository.GetUser2(userName);

						if(u2 != null)
						{
							var theLoginUserInfo = new DataAccess.Models.LoginUserInfo()
							{
								UserID = u2.ID,
								DeptID = u2.DeptId,
								DeptName = u2.DeptName,
								UserName = u2.UserName
							};

							theLoginUserInfo.RoleName = (u2.IsDocReceiver == 1 ? "unitadministrators" : "visitors");

							KPISiteContext.Current.CurrentUser = theLoginUserInfo;

							Response.Redirect("~/Index.aspx");
						}
						else
						{
							Response.Write("用户验证失败.");
						}
					}
				}
				else
				{
					Response.Write("用户验证失败.");
				}
				//var theUser = KPISiteContext.Current.CurrentUser;

				//if(theUser != null)
				//{
				//  Response.Redirect("~/Index.aspx");
				//}
				//else
				//{
				//  Response.Write("用户验证失败.");
				//}
			}
		}
	}
}